package org.wu.framework.lazy.orm.core.persistence.reverse;


import org.wu.framework.lazy.orm.core.persistence.conf.LazyTableFieldEndpoint;
import lombok.Data;
import org.wu.framework.core.CamelAndUnderLineConverter;
import org.wu.framework.core.NormalUsedString;
import org.wu.framework.translation.data.JavaKeyword;

import java.util.Arrays;
import java.util.List;

/**
 * 逆向工程 表信息
 */
@Data
public class ReverseClassLazyTableEndpoint {
    /**
     * 类名
     */
    private String className;
    /**
     * 表名称
     */
    private String tableName;
    /**
     * 描述信息
     */
    private String comment;
    /**
     * 数据库名 schema
     */
    private String schema;
    /**
     * 包名 org.wu.framework.inner.lazy.persistence.conf
     */
    private String packageName;

    /**
     * 输出字段
     */
    private List<LazyTableFieldEndpoint> inLazyTableFieldEndpoints;

    /**
     * 输入字段
     */
    private List<LazyTableFieldEndpoint> outLazyTableFieldEndpoints;

    /**
     * 模型字段
     */
    private List<LazyTableFieldEndpoint> modelLazyTableFieldEndpoints;

    /**
     * 将 class 第一个字母小写 并转处理关键字
     * @return 第一个字母小写 并转处理关键字
     */
    public String getClass2LowName(){
        String className = this.getClassName();
        final String lowercaseFirstLetter = CamelAndUnderLineConverter.lowercaseFirstLetter(className);
        String methodParamName = lowercaseFirstLetter;
        if (Arrays.stream(JavaKeyword.values()).anyMatch(javaKeyword -> javaKeyword.name().toLowerCase().equals(lowercaseFirstLetter))) {
            methodParamName = methodParamName + NormalUsedString.UNDERSCORE;
        }
        return methodParamName;
    }

}
